#include "window.hpp"

#include <stdexcept>

namespace hamster
{
    Window::Window(int width, int height, std::string name) 
    : width(width), height(height), windowName(name)
    {
        initWindow();
    }

    Window::~Window()
    {
        glfwDestroyWindow(window);
        glfwTerminate();
    }

    bool Window::shouldClose()
    {
        return glfwWindowShouldClose(window);
    }

    VkExtent2D Window::getExtent() const
    {
        return VkExtent2D{static_cast<uint32_t>(width), static_cast<uint32_t>(height)};
    }

    void Window::createWindowSurface(VkInstance instance, VkSurfaceKHR* surface)
    {
        if (glfwCreateWindowSurface(instance, window, nullptr, surface) != VK_SUCCESS)
        {
            throw std::runtime_error("failed to create window surface!");
        }
    }

    void Window::initWindow()
    {
        glfwInit();
        // No OpenGL Context
        glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
        // No Window Resize False
        glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);

        window = glfwCreateWindow(width, height, windowName.c_str(), nullptr, nullptr);
    }
}